package com.cndw.kungfu.model.battle;

import java.io.Serializable;

import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.domain.Pet;
import com.cndw.kungfu.domain.SkillMode;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.battlevo.BattlePetVO;

public class FighterCrossPet extends FighterBaseCross implements Fighter, ISkill, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long playerId;
	private int modeId;

	private int[] skillIds;

	public FighterCrossPet() {

	}

	public FighterCrossPet(Pet pet) {
		uniqueId = pet.getId();
		name = pet.getName();
		level = pet.getLevel();
		hp = pet.getHp();
		mp = pet.getMp();
		maxHp = pet.getMaxHp();// 最大体力
		maxMp = pet.getMaxMp();// 最大魔法

		attack = pet.getAttack();// 物理攻击
		defense = pet.getDefense();
		hit = pet.getHit();
		dodge = pet.getDodge();
		crit = pet.getCrit();
		speed = pet.getSpeed();
		tough = pet.getTough();

		modeId = pet.getModeId();
		skillIds = pet.getSkillIds();
		playerId = pet.getPlayerId();
	}

	public long getPlayerId() {
		return playerId;
	}

	public void setPlayerId(long playerId) {
		this.playerId = playerId;
	}

	public int getModeId() {
		return modeId;
	}

	public void setModeId(int modeId) {
		this.modeId = modeId;
	}

	public BattlePetVO toVO() {
		return new BattlePetVO(this);
	}

	public String getIcon() {
		return Context.getPetServer().getPetMode(modeId).getIcon();
	}

	@Override
	public Object getSourceObject() {
		return this;
	}

	@Override
	public int getCurrentSkillId(int nowstep) {
		if (skillIds != null && skillIds.length > 0) {
			try {
				int maxSize = skillIds.length;
				int rateTimes = maxSize > ConstantsModel.petSkillGirdFree ? 2 : 1;
				for (int i = 0; i < rateTimes; i++) {
					int indexId = maxSize == 1 ? 1 : NumberProcesser.mtRand(maxSize);
					int eId = skillIds[indexId - 1];
					SkillMode skillMode = Context.getSkillServer().getSkillMode(eId);
					if (skillMode != null && skillMode.getEffectValue() > 0) {
						if (NumberProcesser.isWinning(skillMode.getBuffRate())) {
							if (getMp() >= skillMode.getConstMp()) {

								return eId;
							} else {
								continue;
							}
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return 0;
	}

	@Override
	public int getScoreCHK() {
		return 0;
	}

	public int[] getSkillIds() {
		return skillIds;
	}

	public void setSkillIds(int[] skillIds) {
		this.skillIds = skillIds;
	}

	@Override
	public int getHurtCoffAdd() {
		return 0;
	}

	@Override
	public int getHurtCoffRemove() {
		return 0;
	}


}
